// pages/progressqryform/progressqryform.js

import config from '../../../utils/config.js'
import { HttpUtil, Target } from '../../../utils/http_util.js'
import { ServiceName, callService } from '../../../utils/store.js'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    //表单对象
    formData: {
      userName: '',
      phone: '',
      signCode: '',
      gender:0,
      age:''
    },

    errormsg: {
      userNameEM: '',
      phoneEM: '',
      signCodeEM: '',
    }

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },
  /**
   * 取消
   * 
   */
  cancel() {
    wx.navigateBack({
      delta: 1
    });
  },
  /**
   * 点击确定按钮
   * 
   */
  submit() {
    //提交
    var that = this;
    var data = that.data.formData;
    var errormsg = that.data.errormsg;
    var isPass = true;

    var uPattern = /^[\u4E00-\u9FA5A-Za-z0-9]+$/;
    if (!uPattern.test(data.userName)) {
      wx.showToast({
        title: '用户名格式不正确',
        icon: 'none',
        duration: 2000
      })
      errormsg.userNameEM = '用户名格式不正确';
      isPass = false;
    }
    var uPhone = /^1(3|4|5|7|8)\d{9}$/;
    if (!uPhone.test(data.phone)) {
      wx.showToast({
        title: '用机号码不正确',
        icon: 'none',
        duration: 2000
      })
      errormsg.phoneEM = '用机号码不正确';

      isPass = false;
    }
    if (!isPass) {
      that.setData({
        errormsg: errormsg
      })
      return false;
    }


    wx.navigateTo({
      url: '/pages/user/relogin/relogin',
    })


  },
  /**
   * 绑定输入框 
   * 
  */
  onFieldChange(event) {
    // var that =this;
    // var em = this.data.errormsg;
    this.data.formData[event.currentTarget.id] = event.detail;
    // em[event.currentTarget.id + 'EM'] = '';
    // that,setData({
    //   errormsg:em
    // })
  },
  /**
 * 选择框改变 
 * 
*/
  onSelectChange(event) {
    var that = this;
    that.data.formData.isPass = event.detail;
    that.setData({
      formData: that.data.formData
    });
  }
})